package com.luckmgr.service.impl;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.common.entity.PageBean;
import com.common.service.BaseService;
import com.common.utils.DateUtil;
import com.luckmgr.dao.LuckRecordMapper;
import com.luckmgr.entity.db.LuckRecord;
import com.luckmgr.service.LuckRecordService;
import com.luckmgr.system.SystemData;
import com.luckmgr.vo.LuckRecordVO;


@Service
public class LuckRecordServiceImpl extends BaseService<LuckRecord> implements LuckRecordService {
	
	LuckRecordMapper luckRecordMapper;
	
	@Resource(name="luckRecordMapper")
    public void initCompanyMapper(LuckRecordMapper luckRecordMapper) {
		this.luckRecordMapper = luckRecordMapper;
        super.setBaseDao(luckRecordMapper);
    }
	
	
	public List<LuckRecord> findRecentlyRecord(Integer aid){
		Map<String,Object> map  = new HashMap<String, Object>();
		map.put("aid", aid);
		map.put("start", 0);
		map.put("pageSize", SystemData.MAX_LOTTO_LIST_SIZE);
		return luckRecordMapper.findRecentlyRecord(map);
	}


	@Override
	public PageBean<LuckRecordVO> selectPageBean(String acode,String uname,Integer page,Integer currentpage) {
		Map<String,Object> map  = new HashMap<String, Object>();
		map.put("acode", acode);
		map.put("name", uname);
		Integer totalPages = luckRecordMapper.selectCount(map);
		PageBean<LuckRecordVO> pageBean = new PageBean<LuckRecordVO>();
		pageBean.setPageSize(currentpage);
		pageBean.setCurrentPage(page);
		pageBean.setTotalResults(totalPages);
		map.put("start", pageBean.getStart());
		map.put("pageSize", pageBean.getPageSize());
		List<LuckRecord> list = luckRecordMapper.selectListPage(map);
		if(null != list && list.size()>0){
			List<LuckRecordVO> volist = new ArrayList<LuckRecordVO>();
			for(LuckRecord luckRecord :list){
				LuckRecordVO luckRecordVO = new LuckRecordVO();
				luckRecordVO.setPname(luckRecord.getPrizeName());
				luckRecordVO.setPtime(DateUtil.format(luckRecord.getPrizeTime(), "yyyy-MM-dd"));
				volist.add(luckRecordVO);
			}
			pageBean.setData(volist);
		}
		
		return pageBean;
	}
}